<template>
  <div>
    <div class="block" v-for="fit in fits" :key="fit">
    <span class="demonstration">{{ fit }}</span>
     <el-image 
    style="width: 100px; height: 180px"
    :src="url" 
    :preview-src-list="srcList">
  </el-image>
  </div>
    <!-- 按钮 -->
    <div class="btns">
            <el-form size="small" inline style="text-align:center">
              <br>
        <el-form-item   color="#FF0000" label="名称" >
          <el-input v-model="param.name" placeholder="请输入内容" auto auto-complete="true" inline style="text-align:center"></el-input>
        </el-form-item>
        <el-form-item> 
          <el-button  size="small" type="primary" icon="el-icon-search" align="center" @click="loadgreenhouses">搜索</el-button>
        </el-form-item>
      </el-form>
        <div style="text-align:right">
    <el-button size= "small" type="warning" round  @click="downloadHandler">导出</el-button>
        <el-button size="small"  type="success" round  @click="toAddHandler">新增</el-button> 
 </div>
      </div>
    <!-- /按钮 -->
    <!-- {{greenhouse}} -->
    <!-- 表格 -->
    <el-table size="small" :data="greenhouses">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="名称" prop="name" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center"></el-table-column>
      <el-table-column label="气温" prop="temperature" align="center"></el-table-column>
      <el-table-column label="空气湿度" prop="airHumidity" align="center"></el-table-column>
      <el-table-column label="土壤湿度" prop="soilHumidity" align="center"></el-table-column>
      <el-table-column label="图片" prop="photo" align="center" width="140px">
        <template slot-scope="scope">
          <br>
          <div style="width:120px;border-radius:5px;height:100px;over-flow:hidden" >
            <img :src="scope.row.photo" alt="" style="width:100%">
          </div>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
      <el-table-column label="用户Id" prop="userId" align="center"></el-table-column>
      <el-table-column label="操作" width="100" align="center">
             <template slot-scope="scope">
          <el-button type="primary"  size="mini" icon="el-icon-edit"  @click="editHandler(scope.row)">修改</el-button >
          <br>
          <br>
          <el-button type="danger" size="mini" icon="el-icon-delete"  @click="deleteHandler(scope.row)">删除</el-button >
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import {get,post,del} from '@/utils/request'
export default {
  // 页面数据
  data(){ 
    return {
      param:{},
     greenhouses:[]
    }
  },
  methods:{
     downloadHandler(){
      window.location.href = "http://8.131.68.179:9999/greenhouse_greenhouse/download?name="+this.param.name
    },
        // 修改事件处理函数
    editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/greenhouse/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
        deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/greenhouse_greenhouse/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadgreenhouses();
        });
      });
    },
    toAddHandler(){
      this.$router.push("/greenhouse/create")
    },
  loadgreenhouses(){
  let url = "http://8.131.68.179:9999/greenhouse_greenhouse/query"
  get(url,this.param).then(resp => {
        this.greenhouses = resp.data;
      })
    }
},
  // 页面渲染的时候会调用的函数
  created(){
    this.loadgreenhouses();
  },
}
</script>
<style scoped>
.el-form{
  background:rgba(9, 189, 150, 0.89);
}
</style>